<%@page import="transfer.Address"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="transfer.Commodity"%>
<%@page import="content.CommodityContent"%>
<%@page import="transfer.Comment"%>
<%@page import="transfer.Order"%>
<%@page import="content.OrderContent"%>
<%@page import="java.util.ArrayList"%>
<div class="block-header" id="id_order" value="<%=request.getParameter("id")%>" >Order #<%=request.getParameter("id")%></div>

<%
    Order order = OrderContent.getOrder(new Integer(request.getParameter("id")));
    ArrayList commentList = OrderContent.getAllCommentsForOrder(order);
    HashMap goodsList = order.getCommodities();
    Iterator iterator = goodsList.keySet().iterator();
    if (commentList.size() != 0) {
        Comment comment;
%>
<div class="box">

    <table class="table" rules=all>
        <tr>
            <td>Date</td>
            <td>State</td>
            <td>User name</td>
            <td>Comment</td>
        </tr>
        <%
            for (int j = 0; j < commentList.size(); j++) {
                comment = (Comment) commentList.get(j);
        %>
        <tr>
            <td><%=comment.getCommentDate()%></td>
            <td><%=comment.getOrderState().getNameOrderState()%></td>
            <td>
                <%
                    if (comment.getUser() != null) {
                        out.print(comment.getUser().getFirstName() + " " + comment.getUser().getLastName());
                    } else {
                        out.print("Anonymous customer");
                    }
                %>
            </td>
            <td><%=comment.getCommentText()%></td>
        </tr>
        <%
            }
        %>
    </table>

</div>
<%
    }
%>
<br/>

<table id="cart-table" border="0" rules=rows bordercolor="#efefef">
    <tr>
        <td width="100px">Items</td>
        <td></td>
        <td width="60px">Amount</td>
        <td width="120px"  style="text-align: right;">Price</td>
    </tr>
    <%
        String link = "../index.jsp?content=view&id=";
        Commodity commodity;
        Object key;
        while (iterator.hasNext()) {
            key = iterator.next();
            commodity = (Commodity) key;
    %>
    <tr>
        <td>
            <a href="<%= link + commodity.getIdCommodity()%>" target="_blank">
                <img src="../images/commodity/<%=commodity.getImage()%>"/>
            </a>
        </td>
        <td><a href="<%= link + commodity.getIdCommodity()%>" target="_blank"><%=commodity.getNameCommodity()%></a></td>
        <td><%=goodsList.get(key)%></td>
        <td style="text-align: right;"><b><%=commodity.getPrice() + " $"%></b></td>
    </tr>
    <%
        }
    %>
</table>
<div style="width: 854px; text-align: right; font-size: 16px; font-weight: bold; margin: 5px 0px 5px 0px; padding-top: 15px;">
    <span style="margin-right: 70px;">Total:</span><%=order.getCostCommodities()%>
</div>
<div class="table-view">
    <div>Current state:</div><%=order.getOrderState().getNameOrderState()%><br/>
    <div>Customer name:</div><%
        if (order.getCustomer() == null) {
            out.print("Anonymous customer");
        } else {
            out.print(order.getCustomer().getFirstName() + " " + order.getCustomer().getLastName());
        }
    %>
    <br/>
    <div>Location:</div><%
        if (order.getAddress() != null) {
            out.print(order.getAddress());
        } else {
            out.print(order.getCustomer().getAddress());
        }
    %><br/>
    <div>Distance:</div><%=order.getDistance()%><br/>
    <div>Shipment price:</div><%=order.getCostDelivery() + " $"%><br/>
    <div>Total price:</div><%=order.getTotalCost() + " $"%><br/>    
</div>

<h3>Comment</h3>
<textarea id="area" maxlength="1000"></textarea>
<div style="width: 100%; text-align: center;">
    <input type="button" value="Delivery" id="delivery_btn" /><br/>
</div>